﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.SocialData;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;

namespace Schwazzle.Core.Services
{
    public class SchwazzleService
    {
        public void CaptureChangesForTaggedItems(string SiteName, string TagName, string UsernameWithDomain)
        {
            TagsService tagsService = new TagsService(SiteName);
            IFeedService feedService = new RavenFeedService();
            List<SPListItem> changedItems = tagsService.GetListItemChanges(TagName, UsernameWithDomain);
            foreach (SPListItem changedItem in changedItems)
            {
                //TODO: get mapping from list
                DateTime createdDate = (DateTime)changedItem["Created"];
                feedService.CreateFeedEntry("Item added with title " + changedItem.Title + " in list " + changedItem.ParentList.Title, UsernameWithDomain, createdDate);
            }
        }

        public void CaptureChangesForColleaguesTaggedItems(string SiteName, string TagName, string UsernameWithDomain)
        {
            TagsService tagsService = new TagsService(SiteName);
            IFeedService feedService = new RavenFeedService();
            List<SPListItem> changedItems = tagsService.GetColleaguesTags(TagName, UsernameWithDomain);
            foreach (SPListItem changedItem in changedItems)
            {
                //TODO: get mapping from list
                DateTime createdDate = (DateTime)changedItem["Created"];
                feedService.CreateFeedEntry("Item added with title " + changedItem.Title + " in list " + changedItem.ParentList.Title, UsernameWithDomain, createdDate);
            }
        }
    }
}
